package com.fj.user.service.impl;

import com.fj.domain.User;
import com.fj.user.dao.UserDao;
import com.fj.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author fj
 * @date 2024/3/11 23:54
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User getUser(Integer uid) {
        return userDao.getById(uid);
    }

    @Override
    public User reduceMoney(Integer uid, Integer money) {
        User user = userDao.getById(uid);
        if (user.getMoney()<money){
            throw new RuntimeException("余额不足");
        }
        user.setMoney(user.getMoney()-money);
        return userDao.save(user);
    }
}
